
module.exports = app => {

    return class CommentController extends app.Controller {
        // async index() {
        //     let forumTypeId = this.ctx.request.query.forumTypeId;
        //     let type = await this.ctx.service.forum.forumType();
        //     await this.ctx.render('forum/topic/index.js', {
        //         type,
        //         forumTypeId
        //     });
        // }

        /**
         * 帖子评论详情
         * @returns {Promise<void>}
         */
        async post() {
            let id = this.ctx.params.id;

            let comment = await this.service.comment.detail({ id });

            await this.ctx.render('forum/comment/index.js', {
                comment
            });
        }

        /**
         * 资讯评论详情
         * @returns {Promise<void>}
         */
        async information() {
            let id = this.ctx.params.id;

            let comment = await this.service.review.detail({ id });
            await this.ctx.render('information/comment/index.js', {
                comment
            });
        }

        async grow() {
            let id = this.ctx.params.id;
            let comment = await this.service.review.detail({ id });
            await this.ctx.render('member/grow/comment/index.js', {
                comment
            });
        }

        /**
         * 资讯评论列表
         * @returns {Promise<void>}
         */
        async list() {
            let params = this.ctx.request.query;

            let id = params.id;
            let pageNo = params.pageNo;
            let pageSize = params.pageSize;
            let type = params.type;

            if (!type){
                type = 4;
            }

            let list = await this.ctx.service.review.list({id, pageNo, pageSize, type});
            this.success(list);
        }

        /**
         * 资讯评论列表
         * @returns {Promise<void>}
         */
        async informationDetailList() {
            let params = this.ctx.request.query;

            let id = params.id;
            let pageNo = params.pageNo;
            let pageSize = params.pageSize;

            let list = await this.ctx.service.review.reviewList({id, pageNo, pageSize});
            this.success(list);
        }

        /**
         * 帖子评论列表
         * @returns {Promise<void>}
         */
        async postList() {
            let params = this.ctx.request.query;

            let id = params.id;
            let pageNo = params.pageNo;
            let pageSize = params.pageSize;

            let list = await this.ctx.service.comment.list({id, pageNo, pageSize});
            this.success(list);
        }

        async postDetailList() {
            let params = this.ctx.request.query;

            let id = params.id;
            let pageNo = params.pageNo;
            let pageSize = params.pageSize;

            let list = await this.ctx.service.comment.getCommentByCommentId({id, pageNo, pageSize});
            this.success(list);
        }


        async postAdd() {
            let params = this.ctx.request.body;

            //type 1.评价 2.回复
            let type = params.type;

            if (type == 1) {
                let content = params.content;
                let id = params.id;

                let list = await this.ctx.service.comment.add({
                    forumPostId: id,
                    content
                });
                return this.success(list);
            } else if (type == 2) {//回复
                let content = params.content;
                let id = params.id;

                let list = await this.ctx.service.comment.sendTopic({
                    commentPostId: id,
                    sign: 1,
                    content
                });
                return this.success(list);
            }

            return this.success();
        }

        async informationAdd() {
            let params = this.ctx.request.body;

            //type 1.评价 2.回复
            let type = params.type;

            if (type == 1) {
                let content = params.content;
                let id = params.id;

                let list = await this.ctx.service.review.comment({
                    objectId: id,
                    content,
                    objectType: 4  //默认为4  对资讯评论
                });
                return this.success(list);
            } else if (type == 2) {//回复
                let content = params.content;
                let id = params.id;

                let list = await this.ctx.service.review.sendTopic({
                    commentId: id,
                    sign: 1,
                    content
                });
                return this.success(list);
            } else if (type == 3) {//回复
                let content = params.content;
                let id = params.id;

                let list = await this.ctx.service.review.comment({
                    objectId: id,
                    content,
                    objectType: 3  //默认为4  对资讯评论
                });
                return this.success(list);
            }

            this.success();

        };
    }
}
